// Xml_Http.h: interface for the CXml_Http class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_XML_HTTP_H__1D6B0ACD_93CD_4886_8CF5_6F0D94B6C35F__INCLUDED_)
#define AFX_XML_HTTP_H__1D6B0ACD_93CD_4886_8CF5_6F0D94B6C35F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include <atlbase.h>
#include <comdef.h>
#include <string>
#include "./CXml/Xml.h"

class CXml_Http  
{
#define _IS_VALID(x) do{if(!is_valid()) return (x);}while(0)
public:
	bool append_header(const char* pszName, const char* pszVal);
	bool open(const char* pszUrl, const char* pszMethod = "POST", const char* pszUser = NULL, const char* pszPwd = NULL);
	bool send_str(const char* pszData = NULL);
	bool retry_send_str(const char* pszData = NULL, int retry_times = 3, DWORD sleep_time = 300);
	bool send_bin(const char *pszData = NULL, size_t nLen = 0);
	bool retry_send_bin(const char *pszData = NULL, size_t nLen = 0, int retry_times = 3, DWORD sleep_time = 300);
	bool recv(CString &strData,const char *charsetName = "UTF-8");

	bool is_valid();

	bool close(){return true;}
	const char* get_err_msg(){return m_err.c_str();}
	void set_err_msg(const char* p)
	{
		m_err = p;

	}
	bool get_response_header(const char* name, CString& val, bool all_header = false);
	
	CXml_Http();
	virtual ~CXml_Http();

protected:
	bool __init();
	void __release();
	static bool __to_variant(const char* pBuffer,VARIANT* vt, long len);
	

	void __ser_no_err() { m_err = "";}
	

protected:
	std::string m_url;
	std::string m_password;
	std::string m_userid;
	std::string m_err;
	MSXML2::IXMLHTTPRequestPtr m_req_ptr;
	bool m_bValid;
};

#endif // !defined(AFX_XML_HTTP_H__1D6B0ACD_93CD_4886_8CF5_6F0D94B6C35F__INCLUDED_)
